<template>
  <a-row type="flex" style="flex-flow: inherit;">
    <a-col :flex="toggle?'260px':'30px'" style="margin-right: 12px;background-color: #fff;">
      <depart-tree :rootOpened="true" :multi="false" @ok="getTreeData" @toggleBool="toggleBool" />
    </a-col>
    <a-col flex="auto">
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="ruleForm" :model="queryParam">
            <z-form-item :datas="fieldArr" :form="queryParam" :gutter="8" :toggle="toggleSearchStatus">
              <a-col :span="4" slot="submit-action">
                <a-space :size="6">
                  <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                  <a-button @click="onResetForm" icon="reload">重置</a-button>
                </a-space>
              </a-col>
            </z-form-item>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <!-- 操作按钮区域 -->
<!--        <div class="table-operator">-->
<!--          <div>-->
<!--            <a-button>导出</a-button>-->
<!--          </div>-->
<!--        </div>-->
        <div style="margin-bottom: 20px">
          <a-alert type="warning" banner closable v-if="lookTer">
            <div slot="message">
              <span>检测出</span><span style="color: #e1854a;margin: 0 5px">{{ SelectNum }}</span><span>处数据异常</span>
              <a style="margin-left: 20px" @click="lookRouter(1)">点击查看</a>
            </div>
          </a-alert>
          <a-button v-else @click="lookRouter(2)">返回</a-button>
        </div>
        <!-- 表格展示 -->
        <div class="table-page-content" v-if="lookTer">
          <z-table
            ref="table"
            rowKey="key"
            :showAlert="false"
            :showSelection="false"
            :loading="loading"
            :columns="columns"
            :dataSource="pageData"
            @selectedRow="onSelectedRow"
            @change="onTableChange"
          />
        </div>
        <div class="table-page-content" v-else>
          <z-table
            ref="table1"
            rowKey="id"
            :showAlert="false"
            :showSelection="false"
            :loading="loading"
            :columns="columns1"
            :dataSource="pageData1"
            @selectedRow="onSelectedRow"
            @change="onTableChange"
          />
        </div>
        <!--弹窗区域-->
<!--        <handle-modal ref="handleModalRef" @ok="modalFormOk" />-->
<!--        <special-population-modal ref="specialPopulationModalRef" />-->
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
import departTree from '../../modules/departTree'
import handleModal from '../../modules/handleModal'
import specialPopulationModal from '../../checkManage/specialPopulation/modules/AddModal'
import {listFor,listForm} from "@views/sjsk/modules/list";
import {pageNew} from "@api/sjsk/receiveCase";
import {abnormalPageNew, abnormalSelectNum, removeException} from "@api/sjsk/archives";

export default {
  components: { departTree, handleModal, specialPopulationModal },
  mixins:[listFor],
  data() {
    return {

      lookTer:true,
      pageData1:[],
      toggle: true,
      selectKeys: [],
      queryParam: {},
      /* 查询折叠 */
      toggleSearchStatus:true,
      fieldArr: [
        {label: '姓名', prop: 'name', tagType: 'input', span: 5},
        {label: '身份证号', prop: 'identification', tagType: 'input', span: 5},
        {label: '当前状态', prop: 'status', tagType: 'dict-select', dictCode:'Dqtype', span: 5},
        {label: '监所类型', prop: 'dataType', tagType: 'dict-select', dictCode:'prisons_type', span: 5}
      ],
      columns: [
        {
          title: '姓名',
          dataIndex: 'realName',
          width: 60,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '性别',
          width: 40,
          align: 'left',
          dataIndex: 'sex',
          customRender: text => {
            if(text === 1){
              return '男'
            } else {
              return '女'
            }
          }
        },
        {
          title: '身份证号',
          dataIndex: 'identityCard',
          width: 110,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '强戒所',
          dataIndex: 'durgRehabilitatioName',
          width: 60,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '当前状态',
          dataIndex: 'isLeftOffice',
          width: 80,
          align: 'center',
          customRender: text => {
           if(text === '1'){
             return '已出所'
           }
           if(text === '2'){
             return '待出所'
           }
           else {
             return '在所'
           }
          }
        },
        {
          title: '入所时间',
          dataIndex: 'admissionTime',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '决定机关',
          dataIndex: 'decisionOrgan',
          width: 80,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '出所原因',
          dataIndex: 'reasonGoOut',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '出所日期',
          dataIndex: 'estimatedTime',
          width: 80,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text?text:'----'} length={14} />
          }
        },
        {
          title: '监所类型',
          dataIndex: 'dataSource',
          width: 80,
          align: 'center',
          customRender: text => {
            if(text === 1){
              return '公安监所'
            }
            if(text === 2){
              return '司法监所'
            }
            else{
              return '----'
            }
          }
        },
        {
          title: '操作',
          width: 120,
          align: 'center',
          dataIndex: 'action',
          customRender: (text, record, index) => {
            return (
              <a-space size={6}>
                <a type="link" style={'padding:0'} onClick={event => this.handleModal(record)}>查看</a>
              </a-space>
            )
          }
        }
      ],
      columns1: [
        {
          title: '姓名',
          dataIndex: 'realName',
          width: 60,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '性别',
          width: 40,
          align: 'left',
          dataIndex: 'sex',
          customRender: text => {
            if(text === 1){
              return '男'
            } else {
              return '女'
            }
          }
        },
        {
          title: '身份证号',
          dataIndex: 'identityCard',
          width: 110,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '强戒所',
          dataIndex: 'durgRehabilitatioName',
          width: 60,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '当前状态',
          dataIndex: 'isLeftOffice',
          width: 80,
          align: 'center',
          customRender: text => {
            if(text === '1'){
              return '已出所'
            }
            if(text === '2'){
              return '待出所'
            }
            else {
              return '在所'
            }
          }
        },
        {
          title: '入所时间',
          dataIndex: 'admissionTime',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '决定机关',
          dataIndex: 'decisionOrgan',
          width: 80,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '出所原因',
          dataIndex: 'reasonGoOut',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '出所日期',
          dataIndex: 'estimatedTime',
          width: 80,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '监所类型',
          dataIndex: 'dataSource',
          width: 80,
          align: 'center',
          customRender: text => {
            if(text === 1){
              return '公安监所'
            } else {
              return '司法监所'
            }
          }
        },
        {
          title: '操作',
          width: 120,
          align: 'center',
          dataIndex: 'action',
          customRender: (text, record, index) => {
            return (
              <a-space size={6}>
                <a type="link" style={'padding:0'} onClick={event => this.handleModal(record)}>查看</a>
                <a type="link" style={'padding:0'} onClick={event => this.handleEnty(record)}>编辑</a>
                <a type="link" style={'padding:0'} onClick={event => this.getRemoveException(record.id)}>解除异常</a>
              </a-space>
            )
          }
        }
      ],
      SelectNum:''
    }
  },
  created() {},
  mounted() {
    // this.onQuery()

    this.abnormalSelectNum()

  },
  methods: {
    onResetForm() {
      // this.queryParam = {}
      delete this.queryParam.name
      delete this.queryParam.identification
      delete this.queryParam.status
      delete this.queryParam.dataType
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.refreshTable()
      // this.$refs.ruleForm.ruleForm()
    },
    renovate(){
      this.refreshTable()
    },
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    onQuery() {
      console.log(this.queryParam)
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },

    lookRouter(val){
      if(this.$route.query.Yc === '1'){
        delete this.$route.query.Yc
      }
      this.lookTer = val !== 1;
      if(!this.lookTer){
        this.refreshTableYC()
      } else {
        this.refreshTable()
        this.abnormalSelectNum()
      }
    },

    abnormalSelectNum(){
      abnormalSelectNum().then(ser => {
        this.SelectNum = ser.result
      })
    },
    //主列表请求
    refreshTable() {
      let queryParam = Object.assign({}, this.queryParam, this.pageFilter)
      this.loading = true
      pageNew(queryParam)
        .then(res => {
          console.log(res)
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            if(this.$route.query.Yc === '1'){
              this.lookTer = false
              this.refreshTableYC()
            }
            // this.$refs.table.onClearRowKeys()
          } else {
            // this.$message.error(res.message);
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    //异常列表请求
    refreshTableYC(){
      let queryParam = Object.assign({}, this.queryParam, this.pageFilter)
      this.loading = true
      abnormalPageNew(queryParam)
        .then(res => {
          console.log(res)
          if (res.success) {
            this.pageData1 = res.result ? res.result : {}
            this.loading = false
            // this.$refs.table.onClearRowKeys()
          } else {
            // this.$message.error(res.message);
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    //解除异常
    getRemoveException(val){
      removeException({id:val}).then(ser => {
        console.log(ser)
        if(ser.success){
          this.$message.success(ser.message)
          this.refreshTableYC()
        } else {
          this.$message.error(ser.message)
        }
      }).catch(err => {

      })
    },

    //详情跳转
    handleModal(record) {
      console.log(record)
      this.$router.push({
        path:'/record/recordLook',
        query:{
          id:record.id
        }
      })
    },
    //编辑跳转
    handleEnty(record){
      this.$router.push({
        path:'/record/recordEnty',
        query:{
          id:record.id
        }
      })
    },

    //树形控件
    getTreeData(datas, id) {
      this.queryParam.departmentId = id
      localStorage.setItem('departmentId',JSON.stringify(id))
      this.onQuery()
      console.log(datas)
      console.log(id)
    },
    toggleBool(bool) {
      console.log(bool)
      this.toggle = bool
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
</style>
